package net.cnki.sunny.controller;

import net.cnki.sunny.annotation.OperateLog;
import net.cnki.sunny.base.BaseController;
import net.cnki.sunny.common.ResultVO;
import net.cnki.sunny.model.dto.DataDTO;
import net.cnki.sunny.model.enums.OperateLogEnums;
import net.cnki.sunny.service.DataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class DataController extends BaseController {

    @Autowired
    private DataService dataService;

    @GetMapping("/data/list")
    public List<Map<String, String>> getList() {
        return dataService.getList();
    }


    @PostMapping("/data/search")
    @OperateLog(operateType = OperateLogEnums.OperateType.OPERATE_SEARCH)
    public ResultVO getSearchData(@RequestBody @Validated DataDTO dataDTO) {
        return new ResultVO().success(dataService.getSearchData(dataDTO));
    }


    @PostMapping("/data/search/leaf")
    public ResultVO getSearchLeafData(@RequestBody DataDTO dataDTO) {
        return new ResultVO().success(dataService.selectLeafThemeDataList(dataDTO));
    }

    @PostMapping("/data/search/tree")
    public ResultVO getSearchTreeData(@RequestBody @Validated DataDTO dataDTO) {
        return new ResultVO().success(dataService.getSearchTreeData(dataDTO));
    }

    @GetMapping("/data/text/{id}")
    @OperateLog(operateType = OperateLogEnums.OperateType.OPERATE_BROWSE)
    public ResultVO getTextDataById(@PathVariable("id") String id) {
        return new ResultVO().success(dataService.getTextDataById(id));
    }

    @GetMapping("/data/firstTheme")
    public ResultVO getFirstThemeList() {
        return new ResultVO().success(dataService.selectFirstThemeList());
    }

    @GetMapping("/data/text/{id}/related")
    public ResultVO getTextDataRelated(@PathVariable("id") String id, @RequestParam Integer num) {
        return new ResultVO().success(dataService.getTextDataRelated(id, num));
    }
}
